
import subprocess, shutil, tempfile, unittest, os

# Makes sense to test it?
def cmd(*args):
    assert subprocess.call(args) == 0
class TestSVN(unittest.TestCase):
    def setUp(self):
        self.repo_dir = tempfile.mkdtemp()
        self.work_dir = tempfile.mkdtemp()
        self.repo_url = 'file:///%s' % self.repo_dir
        cmd('svnadmin', 'create', self.repo_dir)
        cmd('svn', 'co', self.repo_url, self.work_dir)
        from codeflow import settings
        settings.CODEFLOW_SCM_REPO = self.repo_url
        if hasattr(settings, 'CODEFLOW_SCM_USER'):
            delattr(settings, 'CODEFLOW_SCM_USER')
        
    def testSimpleMessage(self):
        os.chdir(self.work_dir)
        file('foo.txt', 'w').write('foo')
        cmd('svn', 'add', 'foo.txt')
        cmd('svn', 'ci', 'foo.txt', '-m', 'test message')
        
    def tearDown(self):
        shutil.rmtree(self.work_dir) 
        shutil.rmtree(self.repo_dir)

